<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title></title>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all"/>
    <style>
        .layui-form-item .layui-input-inline {
            width: 150px;
        }

        .layui-form-label {
            padding: 9px 5px;
            width: auto;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title layui_tab_title">
                <li><a href="/admin/rotary_table/index">活动列表</a></li>
                <li><a href="/admin/rotary_table/conf">奖品列表</a></li>
                <li class="layui-this"><a href="javascript:void(0);">领取记录</a></li>
            </ul>
        </div>

        <form class="layui-form" id="sbumitForm">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline ">
                        <label class="layui-form-label">奖品名称:</label>
                        <div class="layui-input-inline" style="width: 200px">
                            <select name="name">
                                <option value="">全部</option>
                                <?php foreach($list as $key=>$value) {?>
                                <option value="{$key}">{$value}</option>
                                <?php }?>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline ">
                        <label class="layui-form-label">奖品类型:</label>
                        <div class="layui-input-inline" style="width: 150px">
                            <select name="award_type">
                                <option value="">全部</option>
                                <option value="0">虚物奖品</option>
                                <option value="1">实物奖品</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline" style="width:80px;">
                        <div class="layui-input-inline" style="width:80px;">
                            <div class="layui-btn" id="submit">
                                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
        <div class="layui-card-body layui-table-body layui-table-main">
            <table id="demo" lay-filter="demo"></table>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: "/layuiadmin/" //静态资源所在路径
    }).extend({
        index: "lib/index", //主入口模块
    }).use(["table", 'form'], function () {
        $ = layui.jquery, form = layui.form, table = layui.table;
        table.render(table_conf());
        $("#submit").click(function () {
            table.render(table_conf());
        })
    });

    function table_conf() {
        return {
            elem: '#demo',
            id: '#demo',
            url: '/admin/rotary_table/history?'  + $("#sbumitForm").serialize(),
            page: {
                curr: 1   //默认从第一页开始搜索
            },
            method: "get",
            //where: $("#sbumitForm").serialize(),
            limit: 20,
            limits: [20, 30, 50, 100],
            text: {
                none: '暂无相关数据！'//默认无数据
            },
            response: {
                statusName: 'code', //数据状态的字段名称，默认：code
                statusCode: 0,//成功的状态码，默认：0
                msgName: 'msg', //状态信息的字段名称，默认：msg
                countName: 'count', //数据总数的字段名称，默认：count
                dataName: 'list', //数据列表的字段名称，默认：data
            },
            cols: [[
                {field: 'id', width: 80, title: 'ID', align: 'center'},
                {field: '', width: 150, title: '活动名称', align: 'center', templet: function (item) {
                        if (item.lottery && item.lottery.name) {
                            return item.lottery.name;
                        }

                        return '-';
                    }
                },
                {field: 'uid', width: 120, title: '领取人ID', align: 'center'},
                {field: '', width: 120, title: '奖品类别', align: 'center', templet: function (item) {
                        switch (item.award_type) {
                            case 0:
                                return '虚物奖品';
                            case 1:
                                return '实物奖品';
                        }

                        return '-';
                    }
                },
                {field: '', width: 150, title: '奖品名称', align: 'center', templet: function (item) {
                        if (item.lottery_award && item.lottery_award.name) {
                            return item.lottery_award.name;
                        }

                        return '-';
                    }
                },
                {field: '', width: 160, title: '奖品图片', align: 'center', templet: function (item) {
                        if (item.lottery_award && item.lottery_award.award_pic) {
                            return '<div class="layui-table-cell laytable-cell-1-0-4"><img style="display: block;margin:0px auto; height: 100%;" src="' + item.lottery_award.award_pic + '"></div>';
                        }

                        return '-';
                    }
                },
                {field: 'lott_num', width: 100, title: '奖品数量', align: 'center'},
                {field: 'draw_time', width: 160, title: '中奖时间', align: 'center'},
                {field: '', width: 120, title: '奖品状态', align: 'center', templet: function (item) {
                        switch (item.award_type) {
                            case 0:
                                if (item.give_status == 0) {
                                    return '待发放';
                                } else {
                                    return '已发放';
                                }
                            case 1:
                                if (item.give_status == 0) {
                                    return '待发货';
                                } else {
                                    return '<font color="red">已发货</font>';
                                }
                        }

                        return '-';
                    }
                },
                {field: 'give_time', width: 160, title: '发放时间', align: 'center'},
                {field: 'express_no', width: 160, title: '运单号', align: 'center', templet: function (item) {
                        if (item.express_no) {
                            return item.express_no;
                        }

                        return '-';
                    }
                },
                {field: '', width: 120, title: '收货人姓名', align: 'center', templet: function (item) {
                        if (item.user_address && item.user_address.name) {
                            return item.user_address.name;
                        }

                        return '-';
                    }
                },
                {field: '', width: 160, title: '收货人地址', align: 'center', templet: function (item) {
                        if (item.user_address && item.user_address.address) {
                            return item.user_address.address;
                        }

                        return '-';
                    }
                },
                {field: '', width: 160, title: '收货人电话', align: 'center', templet: function (item) {
                        if (item.user_address && item.user_address.mobile) {
                            return item.user_address.mobile;
                        }

                        return '-';
                    }
                },
                {field: 'operator ', width: 150, title: '操作人', align: 'center', templet: function (item) {
                        if (item.operator) {
                            return item.operator;
                        }

                        return '系统';
                    }
                },
                {
                    field: '', title: '操作', align: 'center', width: 160, fixed: 'right', templet: function (item) {
                        if (item.award_type == 0) {
                            if (item.give_status == 0) {
                                //return '<a class="layui-btn layui-btn-xs" onclick="budan(' + item['id'] + ')" style="background-color: #1E9FFF"><i class="layui-icon"></i>补单</a>';
                            }

                            return '-';
                        }

                        if (item.give_status == 0) {
                            return '<a class="layui-btn layui-btn-xs" onclick="fahuo(' + item['id'] + ')" style="background-color: #1E9FFF"><i class="layui-icon"></i>发货</a>';
                        }

                        return '<a class="layui-btn layui-btn-xs" onclick="fahuo(' + item['id'] + ')" style="background-color: #1E9FFF"><i class="layui-icon"></i>编辑</a>';
                    }
                },
            ]],
            done: function (res, curr, count) {
                res.list.forEach(function (item, index) {

                });
            },
        };
    }

    /*发货*/
    function fahuo(id) {
        layer.open({
            type: 2,
            title: ["发货信息", 'font-size:16px'],
            content: '/admin/rotary_table/fahuo?id=' + id,
            area: ['620px', '590px'],
            //offset: '0px',
        });
    }

    /**补单*/
    function budan(id) {
        layer.open({
            type: 2,
            title: ["补单", 'font-size:16px'],
            content: '/admin/rotary_table/budan?id=' + id,
            area: ['620px', '590px'],
            //offset: '0px',
        });
    }

</script>
</body>
</html>
